import socket,time,struct,random

if __name__ == '__main__':
    s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)
   
    while 1:
        msg_num=8;
        packet_head = struct.pack('8H',0,0,0,0,msg_num*4,2,0,0)
        packet = packet_head;
        for i in range(1,1+msg_num):
            v_f = random.random()+0.5
            msg = struct.pack('2H',i,v_f)
            packet = packet+msg
        rs = s.sendto(packet,('localhost',3308))
        print 'send 0x2',rs
                
        msg_num=8;
        packet_head = struct.pack('8H',0,0,0,0,msg_num*4,18,0,0)
        packet = packet_head;
        for i in range(1,1+msg_num):
            v_f = random.random()+0.5
            msg = struct.pack('2H',i,v_f)
            packet = packet+msg
        rs = s.sendto(packet,('localhost',3308))
        print 'send 0x2',rs
        
        msg_num=8;
        packet_head = struct.pack('8H',0,0,0,0,msg_num*8,1,0,0)
        packet = packet_head;
        for i in range(40001,40001+msg_num):
            v_f = random.uniform(1, 20)
            msg = struct.pack('2Hf',i,0,v_f)
            packet = packet+msg
        rs = s.sendto(packet,('localhost',3308))
        print 'send 0x1',rs
                
        msg_num=8;
        packet_head = struct.pack('8H',0,0,0,0,msg_num*8,17,0,0)
        packet = packet_head;
        for i in range(40009,40009+msg_num):
            v_f = random.uniform(1, 20)
            msg = struct.pack('2Hf',i,0,v_f)
            packet = packet+msg
        rs = s.sendto(packet,('localhost',3308))
        print 'send 0x11',rs
        
        time.sleep(1)
        
        
                